
package CtrlLayer;
import ModelLayer.Supplier;
import DBLayer.IFDBSupplier;
import DBLayer.DBSupplier;
import java.util.ArrayList;

/**
 * @version 12/22/2011
 * @author Gruppe 4
 */

public class CtrlSupplier 
{
    private IFDBSupplier dbSupp;
    private Supplier supplier;
    
    /**
     * Constructor for class CtrlStandardTask
     */
    public CtrlSupplier()
    {
        dbSupp = new DBSupplier();
        supplier = new Supplier();
    }
    
    /**
     * Method to get all suppliers from the database
     * @param retrieveAssociation
     * @return returns an ArrayList containing suppliers
     */
    public ArrayList<Supplier> getAllSuppliers(boolean retrieveAssociation)
    {
        return dbSupp.getAllSuppliers(true);
    }
    
    /**
     * 
     * @param supplierId int supplierId the id of the Supplier
     * @param retrieveAssociation
     * @return Returns a Supplier object
     */
    public Supplier findSupplier(int supplierId, boolean retrieveAssociation)
    {
        return dbSupp.findSupplier(supplierId,true);
    }
    
    /**
     * 
     * @param name String name the name of the supplier
     * @param address String address the address of the supplier
     * @param phoneNo String phoneNo the landline number of the supplier
     * @param mobileNo String mobileNo the mobile number of the supplier
     * @param email String email the email of the company
     * @param accountInfo String accountInfo the accountInfo of the supplier
     * @param zipCode int zipCode the zipCode of the company
     * @param cvr String cvr the cvr of the company
     * @param comment String comment a comment for the supplier
     * @param typeNo String typeNo the typeNo of the company
     * @param debNo String debNo the debNo of the company
     * @param cusNo String cusNo the cusNo of the company
     * @param sellerName String sellerName the name of the seller for the company
     * @param sellerPhoneNo String sellerPhoneNo the phone number of the seller for the company
     * @param sellerMail String sellerMail the email of the seller for the company
     */
    public void insertNewSupplier(String name, String address, String phoneNo, String mobileNo, String email, String accountInfo, int zipCode, String cvr, String comment, String typeNo, String debNo, String cusNo, String sellerName, String sellerPhoneNo, String sellerMail)
    {
        supplier.setName(name);
        supplier.setAddress(address);
        supplier.setPhoneNo(phoneNo);
        supplier.setMobileNo(mobileNo);
        supplier.setEmail(email);
        supplier.setAccountInfo(accountInfo);
        supplier.setZipCode(zipCode);
        supplier.setCvr(cvr);
        supplier.setComment(comment);
        supplier.setTypeNo(typeNo);
        supplier.setDebNo(debNo);
        supplier.setCusNo(cusNo);
        supplier.setSellerName(sellerName);
        supplier.setSellerPhoneNo(sellerPhoneNo);
        supplier.setSellerMail(sellerMail);
        dbSupp.insertSupplier(supplier);
    }
    
    /**
     * 
     * @param supplierId int supplierId the id of the supplier
     * @param name String name the name of the supplier
     * @param address String address the address of the supplier
     * @param phoneNo String phoneNo the landline number of the supplier
     * @param mobileNo String mobileNo the mobile number of the supplier
     * @param email String email the email of the company
     * @param accountInfo String accountInfo the accountInfo of the supplier
     * @param zipCode int zipCode the zipCode of the company
     * @param cvr String cvr the cvr of the company
     * @param comment String comment a comment for the supplier
     * @param typeNo String typeNo the typeNo of the company
     * @param debNo String debNo the debNo of the company
     * @param cusNo String cusNo the cusNo of the company
     * @param sellerName String sellerName the name of the seller for the company
     * @param sellerPhoneNo String sellerPhoneNo the phone number of the seller for the company
     * @param sellerMail String sellerMail the email of the seller for the company
     * @return returns an int 1 if the method succedes and -1 if the method fails
     */
    public int updateSupplier(int supplierId, String name, String address, String phoneNo, String mobileNo, String email, String accountInfo, int zipCode, String cvr, String comment, String typeNo, String debNo, String cusNo, String sellerName, String sellerPhoneNo, String sellerMail)
    {
        supplier.setSupplierId(supplierId);
        supplier.setName(name);
        supplier.setAddress(address);
        supplier.setPhoneNo(phoneNo);
        supplier.setMobileNo(mobileNo);
        supplier.setEmail(email);
        supplier.setAccountInfo(accountInfo);
        supplier.setZipCode(zipCode);
        supplier.setCvr(cvr);
        supplier.setComment(comment);
        supplier.setTypeNo(typeNo);
        supplier.setDebNo(debNo);
        supplier.setCusNo(cusNo);
        supplier.setSellerName(sellerName);
        supplier.setSellerPhoneNo(sellerPhoneNo);
        supplier.setSellerMail(sellerMail);
        return  dbSupp.updateSupplier(supplier);
    }
      
    /**
     * Method to delete a supplier from the database
     * @param supplierId int supplierId the id of the supplier
     */
    public void deleteSupplier(int supplierId )
    {
        dbSupp.deleteSupplier(supplierId);
    }
}